/*
 * IMTable.h
 */
#ifndef _IMTABLE_H_
#define _IMTABLE_H_

#include <string>
#include <map>
#include <vector>
#include <fstream>
#include <sstream>

using namespace std;

class IMTable
{
public:
	typedef wstring	xstring;
	IMTable(const char fname[]);
	~IMTable()	{}
	vector<xstring> &getCandidate(const string &keys, vector<xstring> &result, const int disable_feature = 0);
	xstring &convertToCompStr(const string &keys, xstring &compstr);
	bool isValidKey(int ch);
	bool addKey(int ch);	
	vector<xstring> &getCandidate(vector<xstring> &result);
	xstring &convertToCompStr(xstring &compstr);
	const string &getProperty(string prop)	{ return prmap[prop]; }
	const int getMaxLen() { return maxlen; }
	xstring &queryCodeStringByChar(const xstring &ch, xstring &msg);
	const enum TABLE_TYPE { NORMAL_TABLE = 1, QUICK_TABLE = 2, FAULT_TABLE  = 4 };
private:
	typedef map<xstring, map<int, vector<string> > >	CharKeyMap;
	typedef map<string, vector<xstring> >	KeyCharMap;
	typedef map<char, xstring>				KeyRootMap;
	typedef map<string, string>				PropertyMap;
	typedef vector<string>					StringVector;
	int		maxlen;
	PropertyMap		prmap;
	KeyCharMap		kcmap[3];
	CharKeyMap		ckmap;
	KeyRootMap		krmap;
	KeyCharMap::iterator	ikc;
	KeyRootMap::iterator	ikr;
	StringVector::iterator	isv;
	StringVector			expandedkeys;
	StringVector& expandWildcardChars(const string &pattern);
	char	star;
	string	expcand;
	string	tmp;
	size_t	pos;
	string	stroke;
	void	parse();
	//static string		m_compstr;
	//static xstring	m_msgbuf;
};
#endif // _IMTABLE_H_